package t327.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import t327.mapper.LoginMapper;
import t327.mapper.RoleMenuRelMapper;
import t327.pojo.Role;
import t327.pojo.RoleMenuRel;
import t327.pojo.font.UserRoleMenuFront;
import t327.service.iter.ILoginService;
import t327.util.MD5Utils;

import java.util.List;

@Service
@Transactional
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private RoleMenuRelMapper roleMenuRelMapper;
    @Override
    public Role userLogin(String rolephone, String rolepassword) {
        //使用MD5转换格式
        String saltMD5 = MD5Utils.getSaltMD5(rolepassword);
        Role role=  loginMapper.queryByPhoneAndPw(rolephone,saltMD5);
        return role;
    }

    @Override
    public Role queryByPhone(String phone) {
        return loginMapper.queryByPhone(phone);
    }

    @Override
    public RoleMenuRel queryRoleMenuFont(Long roleId) {
        return null;
    }

    @Override
    public UserRoleMenuFront queryByRoleId(Long roleId) {
        return roleMenuRelMapper.queryByRoleId(roleId);
    }

    @Override
    public Integer updatePassword(String rolePhone, String rolePassword) {
        return loginMapper.updatePassword(rolePhone,rolePassword);
    }
}
